﻿using System.Device.Location;
using WaitLess.App.Services.Interfaces;
using System.Diagnostics;

namespace WaitLess.App.Services
{
    public class Gps : IGps
    {
        private readonly GeoCoordinateWatcher _geoCoordinateWatcher;

        public Gps()
        {
            _geoCoordinateWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
            _geoCoordinateWatcher.MovementThreshold = 0;
            _geoCoordinateWatcher.PositionChanged += new System.EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(_geoCoordinateWatcher_PositionChanged);

            _geoCoordinateWatcher.Start();
        }

        private void _geoCoordinateWatcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
        {
            Debug.WriteLine("_geoCoordinateWatcher_PositionChanged: " + e.Position.Location.Latitude);
            Debug.WriteLine("_geoCoordinateWatcher_PositionChanged: " + e.Position.Location.Longitude);
        }

        public GeoCoordinate Location
        {
            get
            {
                return _geoCoordinateWatcher.Position.Location;
            }
        }
    }
}
